Properties

$html

$html : string

Contains the HTML content to convert.

Type

string

$text

$text : string

Contains the converted, formatted text.

Type

string

$width

$width : int

Maximum width of the formatted text, in columns.

Set this value to 0 (or less) to ignore word wrapping and not constrain text to a fixed-width column.

Type

int

$charset

$charset : string

Target character encoding for output text

Type

string

$search

$search : array

List of preg* regular expression patterns to search for, used in conjunction with $replace.

Type

array

$replace

$replace : array

List of pattern replacements corresponding to patterns searched.

Type

array

$ent_search

$ent_search : array

List of preg* regular expression patterns to search for, used in conjunction with $ent_replace.

Type

array

$ent_replace

$ent_replace : array

List of pattern replacements corresponding to patterns searched.

Type

array

$callback_search

$callback_search : array

List of preg* regular expression patterns to search for and replace using callback function.

Type

array

$pre_search

$pre_search : array

List of preg* regular expression patterns to search for in PRE body, used in conjunction with $pre_replace.

Type

array

$pre_replace

$pre_replace : array

List of pattern replacements corresponding to patterns searched for PRE body.

Type

array

$pre_content

$pre_content : string

Temp. PRE content

Type

string

$allowed_tags

$allowed_tags : string

Contains a list of HTML tags to allow in the resulting text.

Type

string

$url

$url : string

Contains the base URL that relative links should resolve to.

Type

string

$_converted

$_converted : bool

Indicates whether content in the $html variable has been converted yet.

Type

bool

$_link_list

$_link_list : array

Contains URL addresses from links to be rendered in plain text.

Type

array

$_do_links

$_do_links : bool

Boolean flag, true if a table of link URLs should be listed after the text.

Type

bool

Methods

__construct()

__construct(string  $source = '', bool  $from_file = false, bool  $do_links = true, int  $width = 75, mixed  $charset = 'UTF-8') : mixed

Constructor.

If the HTML source string (or file) is supplied, the class will instantiate with that source propagated, all that has to be done it to call get_text().

Parameters

string $source

HTML content

bool $from_file

Indicates $source is a file to pull content from

bool $do_links

Indicate whether a table of link URLs is desired

int $width

Maximum width of the formatted text, 0 for no limit

mixed $charset

Returns

mixed —

set_html()

set_html(string  $source, bool  $from_file = false) : mixed

Loads source HTML into memory, either from $source string or a file.

Parameters

string $source

HTML content

bool $from_file

Indicates $source is a file to pull content from

Returns

mixed —

get_text()

get_text() : string

Returns the text, converted from HTML.

Returns

string —

Plain text

print_text()

print_text() : mixed

Prints the text, converted from HTML.

Returns

mixed —

set_allowed_tags()

set_allowed_tags(mixed  $allowed_tags = '') : mixed

Sets the allowed HTML tags to pass through to the resulting text.

Tags should be in the form "

", with no corresponding closing tag.

Parameters

mixed $allowed_tags

Returns

mixed —

set_base_url()

set_base_url(mixed  $url = '') : mixed

Sets a base URL to handle relative links.

Parameters

mixed $url

Returns

mixed —

blockquote_citation_callback()

blockquote_citation_callback(mixed  $m) : mixed

Callback function to correctly add citation markers for blockquote contents

Parameters

mixed $m

Returns

mixed —

tags_preg_callback()

tags_preg_callback(array  $matches) : string

Callback function for preg_replace_callback use.

Parameters

array $matches

PREG matches

Returns

string —

Element content

pre_preg_callback()

pre_preg_callback(array  $matches) : string

Callback function for preg_replace_callback use in PRE content handler.

Parameters

array $matches

PREG matches

Returns

string —

PRE content

_convert()

_convert() : mixed

Workhorse function that does actual conversion (calls _converter() method).

Returns

mixed —

_converter()

_converter(string  $text) : mixed

Workhorse function that does actual conversion.

First performs custom tag replacement specified by $search and $replace arrays. Then strips any remaining HTML tags, reduces whitespace and newlines to a readable format, and word wraps the text to $width characters.

Parameters

string $text

Reference to HTML content string

Returns

mixed —

_build_link_list()

_build_link_list(string  $link, string  $display) : mixed

Helper function called by preg_replace() on link replacement.

Maintains an internal list of links to be displayed at the end of the text, with numeric indices to the original point in the text they appeared. Also makes an effort at identifying and handling absolute and relative links.

Parameters

string $link

URL of the link

string $display

Part of the text to associate number with

Returns

mixed —

_convert_pre()

_convert_pre(string  $text) : mixed

Helper function for PRE body conversion.

Parameters

string $text

HTML content

Returns

mixed —

_convert_blockquotes()

_convert_blockquotes(string  $text) : mixed

Helper function for BLOCKQUOTE body conversion.

Parameters

string $text

HTML content

Returns

mixed —

_toupper()

_toupper(string  $str) : string

Strtoupper function with HTML tags and entities handling.

Parameters

string $str

Text to convert

Returns

string —

Converted text

_strtoupper()

_strtoupper(string  $str) : string

Strtoupper multibyte wrapper function with HTML entities handling.

Parameters

string $str

Text to convert

Returns

string —

Converted text